﻿using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using Common.Constants;
using Common.Helper;
using Entities;

namespace DataAccess
{
   public class CountryDataAccess
    {
       
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <value>
        /// The instance.
        /// </value>
        public static CountryDataAccess Instance { get; private set; }

        /// <summary>
        /// Initializes the <see cref="AddressDataAccess" /> class.
        /// </summary>
        static CountryDataAccess() { Instance = new CountryDataAccess(); }



        /// <summary>
        /// Extracts the raw data.
        /// </summary>
        /// <param name="dataReader">The data reader.</param>
        /// <returns></returns>
        private static Country ExtractRawData(IDataRecord dataReader)
        {
            var country = new Country();
                   
            
            if (dataReader["CountryId"] != null)
                country.CountryId = (Guid)dataReader["CountryId"];
           
            country.CountryName = dataReader["CountryName"].ToString();
            return country;


        }
        public Country GetCountry(string countyId)
        {


            var colParameter = new Collection<SqlParameter>
                                   {
                                       new SqlParameter("CountryId", countyId)
                                      
                                       
                                   };
            using (var reader = SqlHelper.ExecuteReader(ProcedureStores.GetCountry, colParameter))
            {
                if (reader.Read())
                {
                    return ExtractRawData(reader);

                }
                return null;
            }
        }
        public int Insert(Country country)
        {
            var colParameter = new Collection<SqlParameter>
                    {
                       new SqlParameter("CountryId",country.CountryId),
                       new SqlParameter("CountryName",country.CountryName)

                    };

            var resuft = SqlHelper.ExecuteNonQuery(ProcedureStores.InsertCountry, colParameter);
            return resuft;
        }
    }
}
